package com.doit.day03.不可变集合

object _06_flatten {
  def main(args: Array[String]): Unit = {
    //压平  本质上，就是将这个字符串 "hello" ==> Array('h','e','l','l','o')
    val arr: Array[String] = Array("hello", "hi", "nvqiang", "tingting")
    val res: Array[Char] = arr.flatten
    res.foreach(println)

    println("==============================")

    //如果你有数组得嵌套，那我会将里面得数组中每一个元素都拿出来，然后放在最外层数组里面
    val arr1 = Array(Array('h','e','l','l','o'),Array('h','i'),Array('n','v'))
    val res2: Array[Char] = arr1.flatten
    res2.foreach(println)

    //他只能干掉一层，不能干掉2层
    val arr3 = List(List(List("hello","hi"),List("hello","hi")),List(List("hello","hi"),List("hello","hi")))
    val res4: List[String] = arr3.flatten.flatten
    //
    println(res4)

  }

}
